package gqz.mvvm.view.custom;

import android.animation.TypeEvaluator;
import android.graphics.PointF;

/**
 * Created by Administrator on 2017/12/9.
 */

public class BezierEvaluator implements TypeEvaluator<PointF> {

    private PointF pointF1, pointF2;

    public BezierEvaluator(PointF p1, PointF p2) {//传入两个控制点
        this.pointF1 = p1;
        this.pointF2 = p2;
    }

    @Override
    public PointF evaluate(float time, PointF startValue, PointF endValue) {
        PointF point = new PointF();

        float timeLeft = 1.0f - time;
        point.x = timeLeft * timeLeft * timeLeft * (startValue.x)
                + 3 * timeLeft * timeLeft * time * (pointF1.x)
                + 3 * timeLeft * time * time * (pointF2.x)
                + time * time * time * (endValue.x);

        point.y = timeLeft * timeLeft * timeLeft * (startValue.y)
                + 3 * timeLeft * timeLeft * time * (pointF1.y)
                + 3 * timeLeft * time * time * (pointF2.y)
                + time * time * time * (endValue.y);

        return point;
    }
}
